package com.isnmp.common.snmp;

import java.io.Serializable;
import java.rmi.Naming;

import com.caucho.hessian.client.HessianProxyFactory;
import com.isnmp.common.base.MyException;
import com.isnmp.common.base.RMINamingServer;
import com.isnmp.common.snmp.impl.RMISNMPAPIImpl;
import com.isnmp.common.snmp.impl.SNMPAPIImpl;
import com.isnmp.common.snmp.impl.SNMPUtils;

public class SNMPFactory implements Serializable {
    public static final int Mode_Local = 1;
    public static final int Mode_Server_Local = 2;
    public static final int Mode_Client = 3;
    public static final int Mode_Client_RMI = 6;
    private static int modeType = 0;
    private static String ip = "127.0.0.1";
    private static SNMPAPI snmpapi;

    /**
     * 
     * @param paramInt1
     * @param paramString
     * @param paramInt2
     * @throws MyException
     */
    public static void init(int paramInt1, String paramString, int paramInt2) throws MyException {
        SNMPUtils.formatCNString("");
        if (snmpapi != null)
            return;
        try {
            modeType = paramInt1;
            System.out.println(paramInt1);
            ip = paramString;
            if (modeType == 2) {
                RMISNMPAPIImpl.startServ();
                snmpapi = SNMPAPIImpl.getInstance();
            } else if (modeType == 6) {
                snmpapi = (SNMPAPI) Naming.lookup("//" + ip + ":" + RMINamingServer.rmiPort + "/SNMPServer");
            } else if (modeType == 1) {
                snmpapi = SNMPAPIImpl.getInstance();
            } else if (modeType == 3) {
                String str = "http://" + paramString + ":" + paramInt2 + "/snmpapi.invok";
                HessianProxyFactory localHessianProxyFactory = new HessianProxyFactory();
                snmpapi = (SNMPAPI) localHessianProxyFactory.create(SNMPAPI.class, str);
            }
            //
            //            else {
            //                snmpapi = SNMPAPIImpl.getInstance();
            //            }
        } catch (Exception localException) {
            localException.printStackTrace();
            throw new MyException(localException);
        }
    }

    public static void loadMib(String paramString) throws MyException {
        SNMPAPIImpl.getInstance().loadMib(paramString);
    }

    public static SNMPAPI getSNMPAPI() throws MyException {
        if (snmpapi == null) {
            throw new MyException("SNMPAPI is NULL, Please check call init() first.");
        }
        return snmpapi;
    }

    public static void main(String[] paramArrayOfString) {
        try {
            init(2, null, 8088);
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }
}